* Listing - IV Models *

clear
use "ESA Lawsuits JAERE IV Models.dta"

* Tables 2 and 3 *

* Use partial to calculate Sargan statistic *

xtivreg2 listed (lcownls_list = lcmeanis_r1 lcmeanoc_r1) lc3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap propcap yr* , fe cluster(lead_region1) first partial(yr*)

* No partial for bootstraps *

xtivreg2 listed (lcownls_list = lcmeanis_r1 lcmeanoc_r1) lc3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap propcap yr* , fe cluster(lead_region1)

* Wild bootstrap t-procedure *

boottest lcownls_list, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest listcap, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest chcap, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest propcap, noci seed (2309487) nonull ptype(equaltail) weight(webb)

* No IV - Table 3*

xtreg listed lcownls_list lc3otherls_eg1 meanpopg meanpopd meanrepv yr* listcap chcap propcap, fe cluster(lead_region1) 

boottest lcownls_list, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest listcap chcap propcap, noci seed (2309487) nonull ptype(equaltail) weight(webb)

* Table 5 *

* Temporal falsification test *

* Do 2sls for 1990 - 2002 with 2004-2016 instruments *

* gen lcmeanis0416 = F14.lcmeanis_r1 
* gen lcmeanoc0416 = F14.lcmeanoc_r1

xtivreg2 listed (lcownls_list = lcmeanis0416 lcmeanoc0416) lc3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap propcap yr* if (year < 2003), fe cluster(lead_region1) first

boottest lcownls_list, noci seed (2309487) ptype(equaltail) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) ptype(equaltail) weight(webb)
boottest meanpopg, noci seed (2309487) ptype(equaltail) weight(webb)
boottest meanpopd, noci seed (2309487) ptype(equaltail) weight(webb)
boottest meanrepv, noci seed (2309487) ptype(equaltail) weight(webb)


* Falsification test: lawsuits for other reasons should have no effect *

xtivreg2 listed (lcownls_eg2 = lcmeanis_r1 lcmeanoc_r1) lc3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap propcap yr*, fe cluster(lead_region1) first

boottest lcownls_eg2, noci seed (2309487) ptype(equaltail) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) ptype(equaltail) weight(webb)
boottest meanpopg, noci seed (2309487) ptype(equaltail) weight(webb)
boottest meanpopd, noci seed (2309487) ptype(equaltail) weight(webb)
boottest meanrepv, noci seed (2309487) ptype(equaltail) weight(webb)

* Sensitivity: Species characteristics and region, state FEs - Table A3 *


ivreg2 listed (lcownls_list = lcmeanis_r1 lcmeanoc_r1) lc3otherls_eg1 meanpopg meanpopd meanrepv mammal amphibian bird reptile bodysize distinct carnivore piscivore invertivore herbivore granivore frugivore nectarivore terrestrial subterr estuarine lacustrine palustrine marine riverine special listcap chcap propcap i.lead_region1 i.year AL-WY , cluster(lead_region1) first

boottest lcownls_list, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest bodysize, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest distinct, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest listcap, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest chcap, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest propcap, noci seed (2309487) nonull ptype(equaltail) weight(webb)

* Different cumulative other lawsuits - Footnote 7 *

* 4 years *

xtivreg2 listed (lcownls_list = lcmeanis_r1 lcmeanoc_r1) lc4otherls_eg1 meanpopg meanpopd meanrepv listcap chcap propcap yr*, fe cluster(lead_region1) first

boottest lcownls_list, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest lc4otherls_eg1, noci seed (2309487) nonull ptype(equaltail) weight(webb)

* 5 years *

xtivreg2 listed (lcownls_list = lcmeanis_r1 lcmeanoc_r1) lc5otherls_eg1 meanpopg meanpopd meanrepv listcap chcap propcap yr*, fe cluster(lead_region1) first

boottest lcownls_list, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest lc5otherls_eg1, noci seed (2309487) nonull ptype(equaltail) weight(webb)

* 6 years *

xtivreg2 listed (lcownls_list = lcmeanis_r1 lcmeanoc_r1) lc6otherls_eg1 meanpopg meanpopd meanrepv listcap chcap propcap  yr*, fe cluster(lead_region1) first

boottest lcownls_list, noci seed (2309487) nonull ptype(equaltail) weight(webb) 
boottest lc6otherls_eg1, noci seed (2309487) nonull ptype(equaltail) weight(webb)

* Polynomials of Instruments *

xtivreg2 listed (cownls_list = cmeanis_r1 cmeanis_r1sq cmeanoc_r1 cmeanoc_r1sq) c3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap propcap yr*, fe cluster(lead_region1) first

boottest cownls_list, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest c3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) weight(webb)

* Graphs for instruments over time - Figure A2 *

twoway (scatter meanis_r1 year, sort), xscale(range(1990 2017)) xlabel(1990(9)2017) by(, title(a. Mean Ideology Score - Trends by Region)) by(lead_region1, legend(off)) xtitle("") ytitle("")

twoway (scatter meanoc_r1 year, sort), xscale(range(1990 2017)) xlabel(1990(9)2017) yscale(range(0 24)) ylabel(0(6)24) by(, title(Number of Old Cases - Trends by Region)) by(lead_region1, legend(off)) xtitle("") ytitle("")

* Summary Statistics - Table A1 *

quietly xtivreg2 listed (lcownls_list = lcmeanis_r1 lcmeanoc_r1) lc3otherls_eg1 meanpopg meanpopd meanrepv yr* listcap chcap propcap, fe cluster(lead_region1) 

sum listed cownls_list cmeanis_r1 cmeanoc_r1 c3otherls_eg1 mammal amphibian bird reptile bodysize distinct meanpopg meanpopd meanrepv if e(sample)

* First stage plots - Figure 3 *

clear
use "First stage graphs_state scale.dta" 

twoway (scatter lawsuits_list meanjscore if lawsuits_list <=20, sort), xtitle(Judicial Ideology Score) ytitle(Number of Lawsuits) legend(off)

twoway (scatter lawsuits_list meanoldc if lawsuits_list <=20, sort), xtitle(Percent of Old Cases) ytitle(Number of Lawsuits) legend(off) 


* Critical Habitat and Expenditures Models - FE on matched sample *

* Matching - Table A2 *

clear
use "ESA Lawsuits JAERE Matching.dta"

* Mahalanobis matching, four neighbors, no caliper *

* Critical Habitat *

psmatch2 treated2, mahal (crithab mammal amphibian bird reptile fish lbodysize monotypic meanrepv lead_region1) out(listed) n(4)
pstest crithab fws mammal amphibian bird reptile fish lbodysize distinct special lead_region1   meanpopg meanpopd meanrepv, both


* Spending *

psmatch2 treated2, mahal (tspendfws mammal amphibian bird reptile fish lbodysize meanrepv) out(listed) n(4)
pstest tspendfws fws mammal amphibian bird reptile fish lbodysize distinct special lead_region1   meanpopg meanpopd meanrepv, both


* Estimation *

clear
use "ESA Lawsuits JAERE FE Models.dta"

keep crithab lcownls_eg2 lc3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap year weight2 lead_region1 lchsize mammal amphibian bird reptile bodysize distinct carnivore piscivore invertivore herbivore granivore frugivore nectarivore terrestrial subterr estuarine lacustrine palustrine marine riverine special meanpopg meanpopd meanrepv AL-WY lcownls_eg ltspend weight8 weight6 weight1 id tspend chsize cownls_eg c3otherls_eg1

* Critical Habitat - Table 4 *

xtreg crithab lcownls_eg2 lc3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap i.year  if(weight2 != .), fe cluster(lead_region1) 

boottest lcownls_eg2, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest listcap, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest chcap, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)

xtreg lchsize lcownls_eg2 lc3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap  i.year if(weight2 != .), fe  cluster(lead_region1) 

boottest lcownls_eg2, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest listcap, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest chcap, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)

** Robustness to omitted state characteristics (Oster 2018) - Table A4 **

quietly tab year, gen(yr)

areg crithab lcownls_eg2 lc3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap yr1 - yr25 if(weight2 != .), absorb(id) cluster(lead_region1) 
psacalc delta lcownls_eg2, rmax(0.91) mcontrol(lc3otherls_eg1 yr1 - yr25)
psacalc delta lc3otherls_eg1, rmax(0.91) mcontrol(lcownls_eg2 yr1 - yr25)

areg lchsize lcownls_eg2 lc3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap yr1 - yr25 if(weight2 != .), absorb(id) cluster(lead_region1) 
psacalc delta lcownls_eg2, rmax(0.9) mcontrol(lc3otherls_eg1 yr1 - yr25)
psacalc delta lc3otherls_eg1, rmax(0.9) mcontrol(lcownls_eg2 yr1 - yr25)

* Alternative Treatment: All lawsuits by environmental groups - Table A5 * 

xtreg crithab lcownls_eg lc3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap i.year if(weight1 != .), fe cluster(lead_region1) 

boottest lcownls_eg, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)


xtreg lchsize lcownls_eg lc3otherls_eg1 meanpopg meanpopd meanrepv listcap chcap i.year if(weight1 != .), fe  cluster(lead_region1) 

boottest lcownls_eg, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)


* Species Characteristics + Administrative Region and State FE - Table A6 *

reg crithab lcownls_eg2 lc3otherls_eg1 mammal amphibian bird reptile bodysize distinct carnivore piscivore invertivore herbivore granivore frugivore nectarivore terrestrial subterr estuarine lacustrine palustrine marine riverine special meanpopg meanpopd meanrepv listcap chcap i.lead_region1 i.year AL-WY if(weight2 != .),  cluster(lead_region1) 

boottest lcownls_eg2, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest bodysize, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest distinct, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest listcap, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest chcap, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)

reg lchsize lcownls_eg2 lc3otherls_eg1 mammal amphibian bird reptile bodysize distinct carnivore piscivore invertivore herbivore granivore frugivore nectarivore terrestrial subterr estuarine lacustrine palustrine marine riverine special meanpopg meanpopd meanrepv listcap chcap i.lead_region1 i.year AL-WY if(weight2 != .),  cluster(lead_region1) 

boottest lcownls_eg2, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest bodysize, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest distinct, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest listcap, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest chcap, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)


* Spending - Table 4 *

xtreg ltspend lcownls_eg2 lc3otherls_eg1 meanpopg meanpopd meanrepv listcap i.year if(weight8 != .), fe cluster(lead_region1) 

boottest lcownls_eg2, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest listcap, noci seed (2309487) nonull ptype(equaltail) weight(webb)

** Robustness to omitted state characteristics (Oster 2018) - Table A4 **

areg ltspend lcownls_eg2 lc3otherls_eg1 meanpopg meanpopd meanrepv listcap yr1 - yr25 if(weight8 != .), absorb(id) cluster(lead_region1) 
psacalc delta lcownls_eg2, rmax(0.8) mcontrol(lc3otherls_eg1 yr1 - yr25)

* Alternative Treatment: All lawsuits by environmental groups - Table A5 * 

xtreg ltspend lcownls_eg lc3otherls_eg1 meanpopg meanpopd meanrepv listcap i.year if(weight6 != .), fe cluster(lead_region1) 

boottest lcownls_eg, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) weight(webb)

* Species Characteristics + Administrative Region FE - Table A6 *

reg ltspend lcownls_eg2 lc3otherls_eg1 mammal amphibian bird reptile bodysize distinct carnivore piscivore invertivore herbivore granivore frugivore nectarivore terrestrial subterr estuarine lacustrine palustrine marine riverine special meanpopg meanpopd meanrepv listcap i.lead_region1 i.year if(weight8 != .),  cluster(lead_region1) 

boottest lcownls_eg2, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest lc3otherls_eg1, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopg, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanpopd, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest meanrepv, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest bodysize, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)
boottest distinct, noci seed (2309487) nonull ptype(equaltail) rep(999999) weight(webb)

* Summary Statistics - Table A1 *

quietly reg ltspend lcownls_eg2 lc3otherls_eg1 mammal amphibian bird reptile bodysize distinct carnivore piscivore invertivore herbivore granivore frugivore nectarivore terrestrial subterr estuarine lacustrine palustrine marine riverine special meanpopg meanpopd meanrepv listcap i.lead_region1 i.year if(weight8 != .),  cluster(lead_region1) 

sum tspend crithab chsize cownls_eg c3otherls_eg1 mammal amphibian bird reptile bodysize distinct meanpopg meanpopd meanrepv if e(sample)



